import Vue from 'vue';
import VueRouter, {RawLocation, RouteConfig} from "vue-router";
import adminRouter from './admin'
import {ErrorHandler} from "vue-router/types/router"

// 防止重复push相同路由报错
// const originalPush = VueRouter.prototype.push;
// VueRouter.prototype.push = function push(location: RawLocation, onResolve?: Function, onReject?: ErrorHandler) {
//     if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
//
//     // @ts-ignore
//     return originalPush.call(this, location).catch((err: any) => err)
// };
//
// // 防止重复replace相同路由报错
// const originalReplace = VueRouter.prototype.replace;
// VueRouter.prototype.replace = function replace(location: RawLocation, onComplete?: Function, onAbort?: ErrorHandler) {
//     if (onComplete || onAbort) return originalReplace.call(this, location, onComplete, onAbort);
//
//     // @ts-ignore
//     return originalReplace.call(this, location).catch((err: any) => err);
// };

Vue.use(VueRouter);

let menu: Array<RouteConfig> = new Array<RouteConfig>();
menu.push(...adminRouter);

const routes: Array<RouteConfig> = [
    {
        path: '/',
        name: 'home',
        component: () => import('../views/Home.vue'),
        children: menu
    },
];

const router = new VueRouter({
    routes
});

export default router
